#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=1005;
ll arr[N],sum[N];
ll ans[N*N];
ll cnt=0;
int main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	ll n;cin>>n;
	for (ll i=1;i<=n;i++){
		cin>>arr[i];
		sum[i]=sum[i-1]+arr[i]; 
	}
	for (ll i=1;i<=n;i++){
		for (ll j=i;j<=n;j++){
			ans[cnt++]=sum[j]-sum[i-1];
		}
	}
	sort(ans,ans+cnt);
	ll minn=1e18;
	for (ll i=1;i<cnt;i++){
		minn=min(minn,ans[i]-ans[i-1]);
	}
	cout<<minn;
	return 0;
} 
